package edu.info.manager.service;

import edu.info.manager.dao.StudentDao;
import edu.info.manager.domain.Student;

public class StudentService {
    private StudentDao stuDao = new StudentDao();

    public boolean add(Student stu) {
        return stuDao.add(stu);
    }

    public boolean isExist(String id) {

        Student[] stus = stuDao.findAllStudent();
        //假设id不存在
        boolean flag = false;
        for (int i = 0; i < stus.length; i++) {
            Student student = stus[i];
            if (student != null && student.getId().equals(id)) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    public Student[] findAllStudent() {
        //1、调用dao中的findAllStudent方法获取学生对象数据
        Student[] stus = stuDao.findAllStudent();
        //2、判断数组中是否有学生信息
        boolean flag = false;
        for (int i = 0; i < stus.length; i++) {
            if (stus[i] != null) {
                flag = true;
                break;
            }
        }

        if (flag) {
            return stus;
        } else {
            return null;
        }
    }

    public void deleteStudentById(String id) {
        stuDao.deleteStudentById(id);
    }

    public void updateStudent(String uid, Student stu) {
        stuDao.updateStudent(uid,stu);
    }
}
